﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KBVault.DAL.Entities;
using NLog;

namespace KBVault.Web.Application
{
    public partial class SettingsPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                txtCompanyName.Text = Settings.Instance.CompanyName;
                txtArticleCount.Text = Settings.Instance.ArticleCountPerCategoryOnHomePage.ToString();
                txtJumbotronText.Text = Settings.Instance.JumbotronText;
                txtTagLine.Text = Settings.Instance.TagLine;
                txtShareThisPubKey.Text = Settings.Instance.ShareThisPublisherKey;
                txtDisqusShortName.Text = Settings.Instance.DisqusShortName;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Settings.Instance.CompanyName = txtCompanyName.Text;
                Settings.Instance.ArticleCountPerCategoryOnHomePage = Convert.ToInt32(txtArticleCount.Text);
                Settings.Instance.JumbotronText = txtJumbotronText.Text;
                Settings.Instance.TagLine = txtTagLine.Text;
                Settings.Instance.ShareThisPublisherKey = txtShareThisPubKey.Text;
                Settings.Instance.DisqusShortName = txtDisqusShortName.Text;
                Settings.Save();
                Settings.Clear();
            }
            catch (Exception ex)
            {
                LogManager.GetCurrentClassLogger().Error(ex.Message);
                throw;
            }
        }

      
    }
}